<template>
    <div class="flex_col_start m5 p10 card" v-if="globalStatus.heat != null">
        <label class="flex_center_self">小部件控制</label>
        <div class="flex_row_center mt5">
            <LabelSwitch name="蒸汽加热器" @change="onClick0" :value="globalStatus.heat.heat_steam_open"/>
            <LabelSwitch class="ml5" @change="onClick1" name="热水加热器" :value="globalStatus.heat.heat_water_open"/>
            <LabelSwitch class="ml5" @change="onClick2" name="v3" :value="globalStatus.heat.v3_open"/>
            <LabelSwitch class="ml5" @change="onClick3" name="v4" :value="globalStatus.heat.v4_open"/>
        </div>
        <div class="flex_row_center mt5">
            <LabelSwitch name="水泵2" @change="onClick4" :value="globalStatus.heat.bucket2_pump"/>
            <LabelSwitch class="ml5" @change="onClick5" name="水泵1" :value="globalStatus.heat.bucket1_pump"/>
            <LabelSwitch class="ml5" @change="onClick6" name="v6" :value="globalStatus.heat.v6_open"/>
            <LabelSwitch class="ml5" @change="onClick7" name="v7" :value="globalStatus.heat.v7_open"/>
        </div>
        <div class="flex_row_center mt5">
            <LabelSwitch name="v2" @change="onClick8" :value="globalStatus.heat.v2_open"/>
            <LabelSwitch class="ml5" @change="onClick9" name="v1" :value="globalStatus.heat.v1_open"/>
            <LabelSwitch class="ml5" @change="onClick10" name="夹管阀" :value="globalStatus.heat.clamp_valve"/>
            <LabelSwitch class="ml5" @change="onClick11" name="截流阀" :value="globalStatus.heat.trun_valve"/>
        </div>
        <div class="flex_row_center mt5">
            <LabelSwitch name="热水泵" @change="onClick12" :value="globalStatus.heat.water_pump"/>
            <LabelSwitch class="ml5" @change="onClick13" name="蒸汽泵" :value="globalStatus.heat.steam_pump"/>
            <LabelSwitch class="ml5" @change="onClick14" name="v8" :value="globalStatus.heat.v8_open"/>
            <LabelSwitch class="ml5" @change="onClick15" name="气泵" :value="globalStatus.heat.air_pump"/>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { globalStatus } from '@/service/info';
import LabelSwitch from '../base/LabelSwitch.vue';
import { runAction } from '@/utils/ui';
import { parts_ctrl } from '@/service/devices/heat';

async function exec(id: number, v: boolean) {
    let n = 1;
    if (v) {
        n = 0;
    }
    await runAction('小部件控制', '', async () => {
        await parts_ctrl(id, n);
    });
}

async function onClick0(v: boolean) {
    await exec(0, v);
}

async function onClick1(v: boolean) {
    await exec(1, v);
}

async function onClick2(v: boolean) {
    await exec(2, v);
}

async function onClick3(v: boolean) {
    await exec(3, v);
}

async function onClick4(v: boolean) {
    await exec(4, v);
}

async function onClick5(v: boolean) {
    await exec(5, v);
}

async function onClick6(v: boolean) {
    await exec(6, v);
}

async function onClick7(v: boolean) {
    await exec(7, v);
}

async function onClick8(v: boolean) {
    await exec(8, v);
}

async function onClick9(v: boolean) {
    await exec(9, v);
}

async function onClick10(v: boolean) {
    await exec(10, v);
}

async function onClick11(v: boolean) {
    await exec(11, v);
}

async function onClick12(v: boolean) {
    await exec(12, v);
}

async function onClick13(v: boolean) {
    await exec(13, v);
}

async function onClick14(v: boolean) {
    await exec(14, v);
}

async function onClick15(v: boolean) {
    await exec(15, v);
}



</script>
